from typing import List
class Solution:
    def threeSum(self, nums: List[int]) -> List[List[int]]:
        ans = [] # type: List[List[int]]
        nums.sort()
        for i, a in enumerate(nums):
            if i > 0 and nums[i] == nums[i-1]:
                continue
            dic = {}
            if a > 0 :break
            for j in range(i+1, len(nums)):
                b = nums[j]
                if b in dic:
                    if dic[b] != "E":
                        ans.append([a,b, dic[b]])
                        dic[b] = 'E'
                else:
                    dic[0-a-b] = b
        return ans
r = Solution().threeSum([0,0,0,0,0,-1,1])
print(r) # [[-1, 1, 0], [0, 0, 0]]